﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Class_KetNoi;

namespace GiaoDien
{
    public partial class uc_TraCuuPhongBan : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_TraCuuPhongBan()
        {
            InitializeComponent();
        }

        private void groupControl3_Paint(object sender, PaintEventArgs e)
        {

        }
        KetNoi_PhongBan kn = new KetNoi_PhongBan();

        public void LoadDuLieu()
        {
            gridControl1.DataSource = kn.LoadDuLieu();
        }
        private void uc_TraCuuPhongBan_Load(object sender, EventArgs e)
        {
            kn.connect();
            LoadDuLieu();
        }
        int flag;
        private void rabMaPhongBan_Click(object sender, EventArgs e)
        {
            flag = 0;
        }

        private void rabTenPhongBan_Click(object sender, EventArgs e)
        {
            flag = 1;
        }
        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            if (flag == 0)
            {
                try
                {
                    gridControl1.DataSource = kn.TraCuu_MaPhongBan(txtNoiDung.Text);
                    errorProvider1.Clear();
                }
                catch (Exception)
                {
                    errorProvider1.SetError(txtNoiDung,"Mã Phòng Ban không có chữ cái!");
                }
            }
            if (flag == 1)
            {
                gridControl1.DataSource = kn.TraCuu_TenPhongBan(txtNoiDung.Text);
            }
        }

        private void btnLamMoi_Click(object sender, EventArgs e)
        {
            LoadDuLieu();
        }
    }
}
